#!/bin/bash

fd_install_source=/usr/local/software

target_file=/etc/profile

home=/niuniu/tools/java

mkdir -pv ${home}

cd ${home}

rm -rf ./*

tar -zxvf ${fd_install_source}/jdk-8u101-linux-x64.gz


# 移除 jdk 环境配置 begin 
sed -i '/^# jdk Environment config/d'  $target_file
sed -i '/^export JAVA_HOME=/d'  $target_file
sed -i '/^export PATH=\$JAVA_HOME/d'  $target_file
sed -i '/^export CLASSPATH=/d' $target_file
# 移除 jdk 环境配置 end

#fd_target_item=`ls -l |grep jdk* |awk '{print $NF}'`

# 配置 jdk 环境变量 begin
echo "# jdk Environment config begin " >> $target_file

echo "export JAVA_HOME=${home}/${fd_target_item}" >> $target_file
echo "export PATH=\$JAVA_HOME/bin:\$PATH" >> $target_file
echo "export CLASSPATH=.:\$JAVA_HOME/lib/dt.jar:\$JAVA_HOME/lib/tools.jar" >> $target_file

echo "# jdk Environment config end " >> $target_file
# 配置 jdk 环境变量 end


source $target_file
